<?php

/**
 * Created by Sven.
 * Date: 2017/1/4
 * Time: 11:02
 */
class DetailAction extends Action {

    public function __construct( $_tpl ) {
        $_model = new ContentModel();
        parent::__construct( $_tpl, $_model );
    }

    public function action() {
        $this->getContent();
    }

    // 展示内容
    public function getContent(){
        if (isset($_GET['id'])){
            $_id = intval($_GET['id']);
            $_row = $this->model->getOne('cms_content', 'id', $_id);
            if ($_row != null && is_object($_row)){

                // 增加访问次数
                $this->setContentCount($_id);

                $this->tpl->assign('data', $_row);
                $this->tpl->assign('content', Tool::unHtml($_row->content));

                $_nav = new NavAction($this->tpl);
                $_nav->getNavById($_row->nav);

            } else {
                Tool::alertBack('警告：未查询到文章');
            }

        } else {
            Tool::alertBack('警告：ID为非法值');
        }
    }

    // 增加文章的点击数
    public function setContentCount($_id){
        if (intval($_id) > 0){
            $this->model->id = intval($_id);
            $this->model->setCount();
        }

    }

}